//M-164 has backblast radius of 90 degrees, 100 meters	TODO: lineIntersectsSurfaces	BUG: Standing behind a unit can block backblast
//k1优化升级 2020.10.12

private ["_caller", "_units", "_pos1", "_pos2", "_BBArc", "_LoS", "_dir"];
_caller = _this select 0; //unit or _veh
_units = nearestObjects [_caller, ["CaManBase"], 12] - [_caller]; //(_caller nearEntities ["CaManBase", 12])
if (count _units < 1) exitWith {};

_gunner = _this select 7;
if (gunner _caller == _gunner) then [{
	_wep = _this select 1;
	_array = _caller weaponDirection _wep;
	_dir = ((_array select 0) atan2 (_array select 1) + 360) % 360; //武器指向
},{
	_dir = getDir _gunner;
}];

{
	_pos1 = getPosASL _caller;
	_pos2 = getPosASL _x;
	_dist = _pos1 distance _pos2;
	if (_dist < 12) then {
		_BBArc = [_pos1, _dir-180, 36, _pos2] call BIS_fnc_inAngleSector; //位置是否在2D扇形区 90
		if (_BBArc && {[0,0,_pos1 select 2] distance [0,0,_pos2 select 2] < 3.5}) then {
			//_LoS = lineIntersects [eyePos _caller,eyePos _x,objNull,_caller]; //有阻挡是true 会穿透地面！
			if ((lineIntersectsSurfaces [eyePos _caller,eyePos _x,_caller,_x,true,1,"FIRE"] isEqualTo []) && {alive _x} && {_x getVariable ['FAR_once_eh',true]} && {_x getVariable ['FAR_Only_one_EH',0] == 0} && {_x getVariable ['FAR_isUnconscious',0] == 0} && {!(_x getVariable ['AT_Revive_isUnconscious',false])} && {lifeState _x != 'INCAPACITATED'} && {lifeState _x != "UNCONSCIOUS"} && {isNull objectParent _x}) then {
				[_x,_dist < (6 + random 3)] remoteExec ["CRS_BBlasted",_x];
				if(_gunner == player)then{cutText ["筒子尾焰冲击到其他单位！", "Plain Down", .5];
				for "_i" from 0 to 1 do {playSound "combat_deafness"}};
			};
		}; //射手背后等效危险3D扇形区半径12米弧长7.5米高3.5*2米，射手与单位之间无阻挡
	};
} forEach _units;

